from machine import FPIOA
from machine import UART
import time

fpio = FPIOA()
#fpio.set_function(5, FPIOA.UART2_TXD)
#fpio.set_function(6, FPIOA.UART2_RXD)

fpio.set_function(11, FPIOA.UART2_TXD)
fpio.set_function(12, FPIOA.UART2_RXD)

uart = UART(UART.UART2, baudrate = 115200, bits = UART.EIGHTBITS, parity = UART.PARITY_NONE, stop=UART.STOPBITS_ONE)

line = None

while line == None:
    line = uart.readline()

print("Received:", line)
uart.write("UART2 Received:{}\n".format(line))




uart.deinit()
'''
data = None

while data == None:
    data = uart.read()

print("Received:", data)
uart.write("UART2 Received:{}\n".format(data))
'''

'''
data = None


while True:
    data = uart.read()
    if data != None:
        print("Received:", data)
        uart.write("UART2 Received:{}\n".format(data))

uart.deinit()
'''


'''
sensor_time = 0
sensor_value = 0

while True:
    message = "time:{} Sensor Value:{}\n".format(sensor_time,sensor_value)
    uart.write(message)
    sensor_value = sensor_value + 1
    sensor_time = sensor_time + 1000
    time.sleep_ms(1000)
'''


'''
data = bytes([0x01, 0x02, 0x03, 0x04]);
while True:
    uart.write(data)
    print("OK")
    time.sleep_ms(1000)


uart.deinit()
'''

'''
while True:
    uart.write(message)
    print("OK")
    time.sleep_ms(1000)
'''
